﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace uzing
{
    public class CThread
    {
        public delegate object ThreadMethod(object obj);
        private Thread thread;
        private ThreadMethod threadMethod;
        private Object param;

        public CThread()
        {
            thread = null;
            threadMethod = null;
        }

        public void Start()
        {
            if (null != thread)
            {
                runApplication();
            }
        }

        public void Stop()
        {
            thread.Abort();
        }

        public void Suspend()
        {
            if (null != thread)
            {
                thread.Suspend();
            }
        }

        private void runApplication()
        {
            while (true)
            {
                threadMethod(param);
            }
        }

        protected void RegisterThreadMethod(ThreadMethod method, object obj)
        {
            threadMethod = method;
            param = obj;
        }
    }
}

